<template lang="html">
  <div class="share_box">
    <h2 v-if="item.share_profit">赚{{item.share_profit}}</h2>
    <p v-if="item.share_profit">只要你的好友通过此链接购买此商品，你就能赚到至少<span>{{item.share_profit}}</span>元的利润哦~</p>
    <div class="share_list">
      <div class="share_item" @click="shareWx">
        <span class="weixin"></span>
        <p>微信</p>
      </div>
      <div class="share_item icon-copy" @click="copyLink" :data-clipboard-text="url">
        <span class="link"></span>
        <p>复制链接</p>
      </div>
    </div>
  </div>
</template>

<script>
import Path from '@/utils/path.js'
import Tool from '@/utils/tool.js'

export default {
  props: {
    item: {
      type: Object,
      value: false
    }
  },
  data () {
    return {
    }
  },
  created () {
    let item = this.$props.item
    let params = '?pid=' + item.product_id + '&item_id=' + item.item_id + '&activity_id=' + item.activity_id + '&activity_name=' + item.activity_name
    let prdUrl = window.location.origin + '/main/shopDetails' + params
    this.url = prdUrl
  },
  methods: {
    shareWx () {
      let item = this.$props.item
      let params = '?pid=' + item.product_id + '&item_id=' + item.item_id + '&activity_id=' + item.activity_id + '&activity_name=' + item.activity_name
      var url = encodeURIComponent(Path() + '/main/shopDetails' + params)
      var title = item.product_name
      var desc = item.product_tips ? item.product_tips : item.product_name
      var imgurl = encodeURIComponent('https://mjmh.meijiameihuo.com/wechat/images/common/logon.png')
      let isClient = Tool.isClient()
      if (isClient) {
        window.location = 'yggshare://title=' + title + '&desc=' + desc + '&imgurl=' + imgurl + '&url=' + url
      } else {
        this.$toast('h5分享微信')
      }
    },
    copyLink () {
      // let item = this.$props.item
      let that = this
      // let params = '?pid=' + item.product_id + '&item_id=' + item.item_id + '&activity_id=' + item.activity_id + '&activity_name=' + item.activity_name
      // let prdUrl = window.location.origin + '/main/shopDetails' + params
      let clipboard = new this.$clipboard('.icon-copy')
      clipboard.on('success', function (e) {
        e.clearSelection()
        that.$toast('复制成功')
      })
    }
  }
}
</script>

<style lang="css" scoped>

</style>
